<template>
  <div class="main-container">
    <!-- 顶部导航菜单 -->
    <div class="top-menu">
      <!-- Logo区域 -->
      <div class="logo-section">
        <div class="logo">
          <el-icon class="logo-icon"><DataBoard /></el-icon>
          <span class="logo-text">溯源管理系统</span>
        </div>
      </div>

      <div class="left-menu">
        <div class="menu-item" :class="{ active: activeMenu === 'company' }">
          <el-button class="menu-btn" @click="switchMenu('company')">
            <el-icon class="menu-icon-item"><OfficeBuilding /></el-icon>
            <span>公司名称</span>
          </el-button>
        </div>
        <div class="menu-item" :class="{ active: activeMenu === 'group' }">
          <el-button class="menu-btn" @click="switchMenu('group')">
            <el-icon class="menu-icon-item"><Management /></el-icon>
            <span>集团管理</span>
          </el-button>
        </div>
        <div class="menu-item" :class="{ active: activeMenu === 'enterprise' }">
          <el-button class="menu-btn" @click="switchMenu('enterprise')">
            <el-icon class="menu-icon-item"><Shop /></el-icon>
            <span>企业管理</span>
          </el-button>
        </div>
        <div class="menu-item" :class="{ active: activeMenu === 'platform' }">
          <el-button class="menu-btn" @click="switchMenu('platform')">
            <el-icon class="menu-icon-item"><Platform /></el-icon>
            <span>平台运营</span>
          </el-button>
        </div>
        <div class="menu-item" :class="{ active: activeMenu === 'system' }">
          <el-button class="menu-btn" @click="switchMenu('system')">
            <el-icon class="menu-icon-item"><Setting /></el-icon>
            <span>系统设置</span>
          </el-button>
        </div>
      </div>

      <div class="right-menu">
        <div class="search-container">
          <el-input
            placeholder="搜索功能或内容..."
            prefix-icon="Search"
            v-model="searchKeyword"
            class="search-input"
            clearable
          />
        </div>

        <div class="notification-area">
          <el-badge :value="3" class="notification-badge">
            <el-icon class="notification-icon"><Bell /></el-icon>
          </el-badge>
        </div>

        <el-dropdown class="user-dropdown" trigger="hover">
          <div class="user-info">
            <el-avatar class="user-avatar" :size="32">
              <el-icon><User /></el-icon>
            </el-avatar>
            <span class="user-name">管理员</span>
            <el-icon class="dropdown-icon"><ArrowDown /></el-icon>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>
                <el-icon><User /></el-icon>个人中心
              </el-dropdown-item>
              <el-dropdown-item>
                <el-icon><Setting /></el-icon>账户设置
              </el-dropdown-item>
              <el-dropdown-item divided>
                <el-icon><SwitchButton /></el-icon>退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>

        <div class="quick-actions">
          <el-tooltip content="应用市场" placement="bottom">
            <el-button class="action-btn" circle>
              <el-icon><Grid /></el-icon>
            </el-button>
          </el-tooltip>
          <el-tooltip content="客户端下载" placement="bottom">
            <el-button class="action-btn" circle>
              <el-icon><Download /></el-icon>
            </el-button>
          </el-tooltip>
        </div>
      </div>
    </div>

    <!-- 面包屑导航 -->
    <div class="breadcrumb-nav">
      <div class="breadcrumb-content">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>
            <el-icon><HomeFilled /></el-icon>
            <span>首页</span>
          </el-breadcrumb-item>
          <el-breadcrumb-item>企业管理</el-breadcrumb-item>
          <el-breadcrumb-item>溯源管理</el-breadcrumb-item>
        </el-breadcrumb>

        <div class="page-info">
          <span class="current-time">{{ currentTime }}</span>
          <el-divider direction="vertical" />
          <span class="weather-info">
            <el-icon><Sunny /></el-icon>
            <span>晴天 25°C</span>
          </span>
        </div>
      </div>
    </div>

    <!-- 功能标签页 -->
    <div class="function-tabs">
      <div class="tabs-container">
        <div class="tab-list">
          <div class="tab-item active" @click="switchTab('trace')">
            <el-icon class="tab-icon"><DataLine /></el-icon>
            <span>溯源管理</span>
            <el-icon class="close-icon" @click.stop="closeTab('trace')"><Close /></el-icon>
          </div>
          <div class="tab-item" @click="switchTab('quality')">
            <el-icon class="tab-icon"><Medal /></el-icon>
            <span>质量检测</span>
            <el-icon class="close-icon" @click.stop="closeTab('quality')"><Close /></el-icon>
          </div>
          <div class="add-tab" @click="addNewTab">
            <el-icon><Plus /></el-icon>
          </div>
        </div>

        <div class="tab-actions">
          <el-dropdown trigger="hover">
            <el-button size="small" text>
              <el-icon><MoreFilled /></el-icon>
            </el-button>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>关闭其他标签</el-dropdown-item>
                <el-dropdown-item>关闭所有标签</el-dropdown-item>
                <el-dropdown-item>刷新当前页面</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </div>

    <!-- 内容区域 -->
    <div class="content-area">
      <router-view />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import {
  Search, Setting, Menu, ArrowRight, Close, Plus, Delete,
  DataBoard, OfficeBuilding, Management, Shop, Platform,
  Bell, User, ArrowDown, SwitchButton, Grid, Download,
  HomeFilled, Sunny, DataLine, Medal, MoreFilled
} from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const activeMenu = ref('enterprise')
const searchKeyword = ref('')
const currentTime = ref('')

// 更新当前时间
const updateTime = () => {
  const now = new Date()
  currentTime.value = now.toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  })
}

let timeInterval: NodeJS.Timeout

onMounted(() => {
  updateTime()
  timeInterval = setInterval(updateTime, 1000)
})

onUnmounted(() => {
  if (timeInterval) {
    clearInterval(timeInterval)
  }
})

const switchMenu = (menu: string) => {
  activeMenu.value = menu
  if (menu === 'enterprise') {
    router.push('/main/EnterpriseManage')
  }
}

const switchTab = (tab: string) => {
  console.log('切换标签:', tab)
}

const closeTab = (tab: string) => {
  console.log('关闭标签:', tab)
}

const addNewTab = () => {
  console.log('添加新标签')
}
</script>

<style scoped>
.main-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
}

/* 顶部菜单样式 */
.top-menu {
  display: flex;
  align-items: center;
  height: 64px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 0 24px;
  color: white;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  position: relative;
  z-index: 1000;
}

.top-menu::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  z-index: -1;
}

/* Logo区域 */
.logo-section {
  margin-right: 40px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 600;
  color: white;
}

.logo-icon {
  font-size: 28px;
  color: #ffd700;
}

.logo-text {
  background: linear-gradient(45deg, #ffd700, #ffed4e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* 左侧菜单 */
.left-menu {
  display: flex;
  height: 100%;
  gap: 8px;
}

.menu-item {
  height: 100%;
  display: flex;
  align-items: center;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.menu-item:hover {
  transform: translateY(-2px);
}

.menu-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
  height: 100%;
  padding: 0 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.menu-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.menu-btn:hover::before {
  left: 100%;
}

.menu-icon-item {
  font-size: 16px;
}

.menu-item.active .menu-btn {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.menu-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 3px;
  background: linear-gradient(45deg, #ffd700, #ffed4e);
  border-radius: 2px;
}

/* 右侧菜单 */
.right-menu {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-left: auto;
}

.search-container {
  position: relative;
}

.search-input {
  width: 280px;
  border-radius: 20px;
}

.search-input :deep(.el-input__wrapper) {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  transition: all 0.3s ease;
}

.search-input :deep(.el-input__wrapper):hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
}

.search-input :deep(.el-input__inner) {
  color: white;
}

.search-input :deep(.el-input__inner)::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.search-input :deep(.el-icon) {
  color: rgba(255, 255, 255, 0.8);
}

/* 通知区域 */
.notification-area {
  position: relative;
}

.notification-badge :deep(.el-badge__content) {
  background: #ff4757;
  border: 2px solid white;
}

.notification-icon {
  font-size: 20px;
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  transition: all 0.3s ease;
}

.notification-icon:hover {
  color: #ffd700;
  transform: scale(1.1);
}

/* 用户下拉菜单 */
.user-dropdown {
  cursor: pointer;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.user-info:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.user-avatar {
  background: linear-gradient(45deg, #ffd700, #ffed4e);
}

.user-name {
  font-size: 14px;
  font-weight: 500;
  color: white;
}

.dropdown-icon {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  transition: transform 0.3s ease;
}

.user-dropdown:hover .dropdown-icon {
  transform: rotate(180deg);
}

/* 快捷操作 */
.quick-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 面包屑导航 */
.breadcrumb-nav {
  background: white;
  padding: 16px 24px;
  border-bottom: 1px solid #f0f0f0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.breadcrumb-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.breadcrumb-content :deep(.el-breadcrumb__item) {
  display: flex;
  align-items: center;
  gap: 4px;
}

.breadcrumb-content :deep(.el-breadcrumb__inner) {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #666;
  font-weight: 500;
}

.breadcrumb-content :deep(.el-breadcrumb__inner:hover) {
  color: #409eff;
}

.page-info {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #666;
  font-size: 14px;
}

.current-time {
  font-family: 'Monaco', 'Consolas', monospace;
  background: linear-gradient(45deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 600;
}

.weather-info {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #ffa726;
}

/* 功能标签页 */
.function-tabs {
  background: white;
  border-bottom: 1px solid #f0f0f0;
}

.tabs-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
}

.tab-list {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tab-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-bottom: none;
  margin-right: 4px;
}

.tab-item:hover {
  background: #e9ecef;
  transform: translateY(-2px);
}

.tab-item.active {
  background: white;
  border-color: #409eff;
  color: #409eff;
  box-shadow: 0 -2px 8px rgba(64, 158, 255, 0.1);
}

.tab-item.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: #409eff;
}

.tab-icon {
  font-size: 16px;
}

.close-icon {
  font-size: 14px;
  opacity: 0.6;
  transition: all 0.3s ease;
  border-radius: 50%;
  padding: 2px;
}

.close-icon:hover {
  opacity: 1;
  background: #f56c6c;
  color: white;
}

.add-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #f8f9fa;
  border: 1px dashed #d0d7de;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #666;
}

.add-tab:hover {
  background: #409eff;
  border-color: #409eff;
  color: white;
  transform: scale(1.1);
}

.tab-actions {
  display: flex;
  align-items: center;
}

/* 内容区域 */
.content-area {
  flex: 1;
  overflow: auto;
  background: #f8f9fa;
  position: relative;
  min-height: 0; /* 确保flex子项能正确收缩 */
}

.content-area::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(120, 219, 255, 0.1) 0%, transparent 50%);
  pointer-events: none;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .logo-text {
    display: none;
  }

  .search-input {
    width: 200px;
  }

  .user-name {
    display: none;
  }
}

@media (max-width: 768px) {
  .top-menu {
    padding: 0 16px;
  }

  .left-menu {
    gap: 4px;
  }

  .menu-btn {
    padding: 0 12px;
    font-size: 12px;
  }

  .menu-icon-item {
    font-size: 14px;
  }

  .search-input {
    width: 150px;
  }

  .quick-actions {
    display: none;
  }

  .breadcrumb-content {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  .page-info {
    font-size: 12px;
  }
}

/* 动画效果 */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tab-item {
  animation: slideIn 0.3s ease;
}

/* 滚动条美化 */
.content-area::-webkit-scrollbar {
  width: 6px;
}

.content-area::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.content-area::-webkit-scrollbar-thumb {
  background: linear-gradient(45deg, #667eea, #764ba2);
  border-radius: 3px;
}

.content-area::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(45deg, #5a6fd8, #6a4190);
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
  .main-container {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  }

  .breadcrumb-nav {
    background: #34495e;
    border-bottom-color: #4a5f7a;
  }

  .function-tabs {
    background: #34495e;
    border-bottom-color: #4a5f7a;
  }

  .tab-item {
    background: #2c3e50;
    border-color: #4a5f7a;
    color: #ecf0f1;
  }

  .tab-item.active {
    background: #34495e;
    color: #3498db;
  }

  .content-area {
    background: #2c3e50;
  }
}
</style>
